package leetcode;

public class _1578 {
    /**
     * 使绳子变成彩色的最短时间
     */
    class Solution {
        public int minCost(String colors, int[] neededTime) {
            int n = colors.length();
            int i=0;
            int ret =0;
            while(i<n){
                char c = colors.charAt(i);
                int maxValue = 0;
                int sum =0;
                while(i<n&&colors.charAt(i)==c){
                    maxValue=Math.max(maxValue,neededTime[i]);
                    sum += neededTime[i];
                    i++;
                }
                ret+=sum - maxValue;
            }
            return ret;
        }
    }
}
